# 加密pdf文件

from PyPDF2 import PdfReader, PdfWriter

def jia_mi(path):
    # 读取文件
    pdf = PdfReader(open(path, 'rb'))
    # pdf.decrypt('pwd123456')    # 当读取pdf有密码时，填写相应的密码
    # 生成新文件

    writer = PdfWriter()
    writer.encrypt('pwd123456')     # 设置密码
    for i, page in enumerate(pdf.pages):
        writer.add_page(page)

    with open('../02.py_pdfFile/05.加密pdf文件.pdf', 'wb') as out:
        writer.write(out)


if __name__ == '__main__':
    jia_mi('../02.py_pdfFile/01.采购合同模板.pdf')
